
const app = getApp();
var dateTimePicker = require('../../utils/dateTimePicker.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    lid: '',
    display: "block",
    first: {
      f1: "../../images/comment3.png",
      f2: "../../images/comment3.png",
      f3: "../../images/comment3.png",
      f4: "../../images/comment3.png",
      f5: "../../images/comment3.png",
    },
    picindex: 0,
    pinfen: 0,
    text: ''
  },

  gettext: function (e) {
    this.data.text = e.detail.value;
  },

  click1: function (event) {
    //console.log(event);
    for (var i in this.data.first) {
      if (i <= event.target.dataset.name) {
        this.data.first[i] = "../../images/five.png";
      } else {
        this.data.first[i] = "../../images/comment3.png";
      }
    }
    console.log(event.target.dataset.name.substring(1, 2));
    this.data.pinfen = event.target.dataset.name.substring(1, 2);
    this.setData({
      first: this.data.first,
      first_star: event.target.dataset.name.substring(1, 2)
    });
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.lid = options.lid;
    this.data.id = options.id;
    console.log("lid:"+options.lid+" id:"+options.id)
  },

  submit: function (e) {
    var that = this;
    var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);

    var time = obj1.dateTimeArray[0][obj1.dateTime[0]] + "-" + obj1.dateTimeArray[1][obj1.dateTime[1]] + "-" + obj1.dateTimeArray[2][obj1.dateTime[2]] + " " + obj1.dateTimeArray[3][obj1.dateTime[3]] + ":" + obj1.dateTimeArray[4][obj1.dateTime[4]] + ":" + obj1.dateTimeArray[5][obj1.dateTime[5]]

    wx.request({
      url: app.globalData.headurl + '/Lfdappoint/updateLfdappoint',
      data: {
        id: that.data.id,
        status:3
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
        //token: app.globalData.token
      },
      success: function (r) {
      
      }
    })
    wx.request({
      url: app.globalData.headurl + '/Lfdlifashi/updateLfdlifashiById',
      data: {
        lid: that.data.lid,
        pinfen: parseInt(that.data.pinfen)
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
        //token: app.globalData.token
      },
      success: function (r) {

      }
    })

    wx.showModal({
      title: '温馨提示',
      content: '亲，授权微信登录后才能正常使用小程序功能',
      success(res) {
        console.log(0)
        console.log(res)
        //如果用户点击了确定按钮
        if (res.confirm) {
          wx.getUserProfile({
            desc: '获取你的昵称、头像、地区及性别',
            success: res => {
              console.log(res.userInfo);
              console.log(1);
  
              wx.request({
                url: app.globalData.headurl + '/Lfdcomment/addLfdcomment',
                data: {
                  lid: that.data.lid,
                  name: res.userInfo.nickName,
                  logo: res.userInfo.avatarUrl,
                  text: that.data.text,
                  time: time,
                  pinfen: parseInt(that.data.pinfen),
                  openid: app.globalData.openid
                },
                method: "POST",
                header: {
                  "content-type": "application/x-www-form-urlencoded;charset=utf-8",
                  //token: app.globalData.token
                },
                success: function (r) {
                  wx.showToast({
                    title: '评价成功',
                  })
                  wx.navigateBack({})
                }
              })
  
  
            },
            fail: res => {
              console.log(2);
              console.log(res)
              //拒绝授权
              wx.showToast({
                title: '您拒绝了请求,不能正常使用小程序',
                icon: 'error',
                duration: 2000
              });
              return;
            }
          });
        } else if (res.cancel) {
          //如果用户点击了取消按钮
          console.log(3);
          wx.showToast({
            title: '您拒绝了请求,不能正常使用小程序',
            icon: 'error',
            duration: 2000
          });
          return;
        }
      }
    });


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})